package com.chenshu.aop.proxy;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import javax.swing.*;
import java.lang.reflect.Method;

/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2024-04-21
 * Time：13:58
 */
public class CGLibMethodInterceptor implements MethodInterceptor {
    private Object target;

    public CGLibMethodInterceptor(Object target) {
        this.target = target;
    }

    /**
     *
     * @param o 代理类
     * @param method 目标方法
     * @param objects 参数列表
     * @param methodProxy
     */
    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println("CGLib动态代理开始");
        Object result = method.invoke(target, objects);
        System.out.println("CGLib动态代理结束");
        return result;
    }
}
